#pragma once 

#include <string>
using namespace std;

#include "pqxx/pqxx"

using namespace pqxx;
using namespace pqxx::internal;

namespace topdbs
{
  template<
    isolation_level ISOLATIONLEVEL=read_committed,
    readwrite_policy READWRITE=read_write>
  class auto_transaction : public basic_transaction
  {
  public:
    typedef isolation_traits<ISOLATIONLEVEL> isolation_tag;

    /// Create a transaction
    /**
     * @param C Connection for this transaction to operate on
     * @param TName Optional name for transaction; must begin with a letter and
     * may contain letters and digits only
     */
    explicit auto_transaction(connection_base &C, const std::string &TName):	//[t1]
      namedclass(fullname("transaction", isolation_tag::name()), TName),
      basic_transaction(C, isolation_tag::name(), READWRITE)
    {  }

    explicit auto_transaction(connection_base &C) :				//[t1]
      namedclass(fullname("transaction", isolation_tag::name())),
      basic_transaction(C, isolation_tag::name(), READWRITE)
    {  }

    virtual ~auto_transaction() throw ()
    {
  #ifdef PQXX_QUIET_DESTRUCTORS
      quiet_errorhandler quiet(conn());
  #endif
    }

    pqxx::result exec(const std::string &Query,
                const std::string &Desc=std::string())
    {
      const string N = (Desc.empty() ? "" : "'" + Desc + "' ");
      return do_exec(Query.c_str());
    }  
  };

  typedef auto_transaction<> auto_work;
}